<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">添加五病调离</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
  
      <div class="formcontent">
        <ul>
          <li>
            <span><em>*</em>登记时间</span>
            <div class="froms">{{datatime()|time}}</div>
          </li>
          <li>
            <span>调离时间</span>
            <div class="froms">
              <el-input placeholder="请选择日期" icon="date" :disabled="true" v-model="formName.dataValue" @click="openPickerdDate()">
              </el-input>
              <mt-datetime-picker ref="picker" type="date" year-format="{value}年" month-format="{value} 月" date-format="{value} 日" v-model="pickerValue" @cancel="handleCanceDate" @confirm="handleConfirmDate"></mt-datetime-picker>
            </div>
          </li>
          <li>
            <span><em></em>选择人员</span>
            <div class="froms">
              <input type="button" v-model="msg" @click="handleClick" class="text_l">
              <mt-popup v-model="popupVisible" position="right" modal=false class="mint-popup-3">
                <app-person v-on:listenToChildEvent="peopleClick" v-on:listencloseclick="clickmodl"></app-person>
              </mt-popup>
            </div>
          </li>
          <li>
            <span>调离病因</span>
            <div class="froms">
              <input type="text" v-model="formName.offTheRecordReason">
            </div>
          </li>
          <li>
            <span>旧岗位</span>
            <div class="froms">
              <input type="text" v-model="formName.oldPosttest">
            </div>
          </li>
          <li>
            <span>新岗位</span>
            <div class="froms">
              <input type="text" v-model="formName.newposttest">
            </div>
          </li>
        </ul>
      </div>
  
    </main>
  </div>
</template>

<script>
  import Person from '@/components/institutionPerson'
  import {
    OffTheRecordAdd,
    InstitutionPerson
  } from '../../api/api';
  import {
    Popup,
    DatetimePicker
  } from 'mint-ui';
  var moment = require('moment');
  export default {
    name: 'add_mrcj',
    components: {
      'mt-popup': Popup,
      'mt-datetime-picker': DatetimePicker,
      'app-person': Person
    },
    data() {
      return {
        msg: '请选择人员',
        getNowFormatDate: null,
        CriteriaList: [],
        //时间
        pickerValue: moment().format('YYYY-MM-DD'),
        formName: {
          dataValue: '',
          offTheRecordReason: '',
          oldPosttest: '',
          newposttest: '',
        },
        value: '',
        //组件
        seachtext: '',
        popupVisible: false,
        closeOnClickModal: false,
        getPerson: [],
        Enterprise: {},
        PageSize: 10,
        institutionPersonname: '',
        institutionPersonunid: '',
      };
    },
    methods: {
      //获取日期
      openPickerdDate() {
        this.$refs.picker.open();
      },
      handleCanceDate() {
        let _this = this
        _this.pickerValue = _this.formName.dataValue
      },
      // 确定按钮 --- 判断该时间是否可选，若可选则把值赋给输入框的dataValue
      handleConfirmDate(val) {
        let _this = this
        _this.formName.dataValue = moment(val).format('YYYY-MM-DD')
      },
      //获取当前时间 
      datatime: function() {
        var moment = require('moment');
        var currentdate = moment().format('YYYY-MM-DD hh:mm:ss');
        return currentdate;
      },
  
      //弹窗
      handleClick: function() {
        this.popupVisible = true
        this.getInstitutionPerson();
      },
      clickmodl: function() {
        this.popupVisible = false
      },
      //获取item
      peopleClick: function(data) {
        this.institutionPersonname = data.name;
        this.institutionPersonunid = data.unid;
        this.clickmodl();
        this.msg = this.institutionPersonname
      },
      //提交方法
      submitForm: function() {
        //定义需要传给通讯的参数：string Data--实体MorningRecord的序列化值 string UserUnid--当前操作用户标识   stringify对象解析字符串 parse字符串解析对象
        // var options = JSON.stringify(this.options);
        let varQueryData = {
          Name: this.institutionPersonname,
          Unid: this.institutionPersonunid,
          //Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,//规范unid
        }
        let varEnterpriseUnid = {
          Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,
          Name: JSON.parse(localStorage.getItem('auth')).enterpriseName,
        }
        let data = {
          RegistrationTime: this.datatime(),
          OffTheRecordTime: moment(this.formName.dataValue).format('YYYY-MM-DD 00:00:00'),
          EnterprisePerson: varQueryData,
          OffTheRecordReason: this.formName.offTheRecordReason,
          OldPost: this.formName.oldPosttest,
          NewPost: this.formName.newposttest,
          varEnterpriseUnid: this.varEnterpriseUnid,
  
        }
        let dataoption = {
          params: {
            Data: JSON.stringify(data),
            UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
          }
        }
        //调取接口
        OffTheRecordAdd(dataoption).then((res) => {
          if (res.success === true) {
            this.$message.success('保存成功');
            this.$router.go(-1);
          } else {
            this.$message.error(res.msg);
          }
        }).catch(function() {
          this.$message.error('网络异常。');
        })
  
      },
      created() {
  
      },
    }
  }
</script>

<style lang="scss">
  
</style>
